import React from 'react';
import { Switch } from 'antd';
import { BiStatus } from '@/common/type/BiStatus';

interface ISwitchProps {
  value?: BiStatus;
  onChange?: (value: BiStatus) => void;
}

// eslint-disable-next-line react/prefer-stateless-function
class ISwitch extends React.Component<ISwitchProps> {
  render() {
    return (
      <Switch
        defaultChecked={this.props.value === 1}
        onChange={(checked: boolean) => {
          if (this.props.onChange) {
            this.props.onChange(checked ? 1 : 0);
          }
        }}
      ></Switch>
    );
  }
}

export default ISwitch;
